Skip to content

fix duplicate axis#64

Open
Tang-SL wants to merge 3 commits intolegolason:masterfrom
Tang-SL:master
Open

fix duplicate axis#64
Tang-SL wants to merge 3 commits intolegolason:masterfrom
Tang-SL:master

Conversation

@Tang-SL
Copy link

@Tang-SL Tang-SL commented Feb 27, 2024

This problem happens sometime after the late of last year (my collegues also had the same problem at a similar time point). I am guessing some package update issues (I am testing under the latest matplotlib 3.8.3). plt.subplots will create empty axis as a pre-set, this will overlap with the new subplot of the whole spectrum, as shown by the figure. Turn off the axis of the first row before making the new subplot will solve the problem.

Another point is at the end of the plot_fig func, I am a spyder user, the plot does not pop up in my window without plt.show(). And I found it is werid to put plt.close(fig) under if self.save_fig == True, so moved it out.

Screenshot 2024-02-27 at 16 29 03

@rudolffu
Copy link
Contributor

rudolffu commented Feb 27, 2024

FYI. My fix was to remove the placeholder axes and make a new one with matplotlib.gridspec.GridSpec: rudolffu/qsofitmore@4ea13fc

    def _PlotFig(...

        if linefit == True:
            nclos = np.max([self.ncomp, 1])
            fig, axn = plt.subplots(nrows=2, ncols=nclos, figsize=(15, 8),
                                    squeeze=False)  # prepare for the emission line subplots in the second row
            gs = axn[0, 0].get_gridspec()
            for axi in axn[0, :]:
                axi.remove()
            ax = fig.add_subplot(gs[0, :])

@Tang-SL
Copy link
Author

Tang-SL commented Feb 29, 2024

Hi Yuming, the gridspec method is better! My method will make the axis of the upper panel empty if there is only one subpanel in the botton row. Thanks!

@legolason
Copy link
Owner

Sorry for the delay. Glad you have solved this problem, Wenke Ren will fix this issue in the next version. Thanks!

@WenkeRen
Copy link
Contributor

Hi Yuming, the gridspec method is better! My method will make the axis of the upper panel empty if there is only one subpanel in the botton row. Thanks!

Thanks for your contribution. I adopted your modification in fixing figure axis problem. But since we prefer keeping the close function and the pull request can only be accept as whole, I can not adopt this pull request.

If you want the figure show up in your IDE, simply set the save_fig option to False. For users running bulk tasks, the displayed figure would cause memory leak.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants